package com.ordersystem.utils;

import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName : CommonUtils
 * @Description : [描述说明该类的功能]
 * @Author : 没用的阿吉
 * @Version : [v1.0]
 * @CreateTime : [2022/11/28-21:06]
 */
@Component
public class CommonUtils {
    //数组为空时返回空字符串
    public String listToChangeString(List list){
        StringBuffer stringBuffer = null;
        try {
            stringBuffer = new StringBuffer();
            for (Object item : list) {
                stringBuffer.append(String.valueOf(item)+",");
            }
            stringBuffer.delete(stringBuffer.length()-1,stringBuffer.length());
        } catch (Exception e) {
            return "";
        }
        return String.valueOf(stringBuffer);
    }
    public  List stringToChangeList(String str,
                                          String separator){
        List<Integer> resultList = new ArrayList<>();
        if (str.indexOf(separator)==-1){
            resultList.add(Integer.valueOf(str));
            return resultList;
        }
        String[] strList = str.split(separator);
        for (String s : strList) {
            resultList.add(Integer.valueOf(s));
        }
        return resultList;
    }

}
